//
//  IBMagicGiftView.m
//  烟花特效
//
//  Created by apple on 15/7/10.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "IBMagicGiftView.h"
#import "IBMagicStar.h"

@interface IBMagicGiftView ()
{
    float _starTime; //播放星星的时间
}
@property (nonatomic,strong) IBMagicStar * magicStarView; //魔幻星星效果

@end

@implementation IBMagicGiftView

-(instancetype)initWithImage:(UIImage *)image Frame:(CGRect)frame StarTime:(float)starTime
{
    self = [super initWithFrame:frame];
    if (self) {
        self.image = image;
        _starTime = starTime;
    }
    return self;
}

-(void)startMagicStar
{
    //星星点缀图
    _magicStarView = [[IBMagicStar alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [self addSubview:_magicStarView];
    
    [self performSelector:@selector(removeStar) withObject:nil afterDelay:_starTime];
}

//多少秒后消失星星
-(void)removeStar
{
    if (_starTime <= 0)
        return;
    
    [UIView animateWithDuration:0.8 animations:^{
        _magicStarView.alpha = 0;
    } completion:^(BOOL finished) {
        [_magicStarView removeFromSuperview];
    }];
}

@end
